package com.im.foodorderingsystem.task;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;

public class HttpGetRequest {

	String url;
	
	public HttpGetRequest(String url){
		this.url=url;
	}
	
	public String send(){
		DefaultHttpClient httpclient = new DefaultHttpClient(
				new BasicHttpParams());
		HttpGet httppost = new HttpGet(url);
		httppost.setHeader("Content-type", "application/json");
		InputStream inputStream = null;
		String result = null;

		try {
			HttpResponse response = httpclient.execute(httppost);
			HttpEntity entity = response.getEntity();
			inputStream = entity.getContent();
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					inputStream, "UTF-8"), 8);
			StringBuilder theStringBuilder = new StringBuilder();
			String line = null;
			while ((line = reader.readLine()) != null) {
				theStringBuilder.append(line + "\n");
			}
			result = theStringBuilder.toString();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (inputStream != null)
					inputStream.close();
			} catch (Exception e) {
			}
		}
		
		System.out.println("HttpGetRequest class");
		
		return result;
	}
}
